Project Overview
This project visualizes crime incidents in Cincinnati for the years 2024 and 2025. It uses Python and Folium to create an interactive map that shows where crimes happened based on latitude and longitude. The goal is to give people a visual way to understand crime patterns in the city.
Install Required Packages
We use folium to create the interactive map.
In [4]:
!pip install folium
Requirement already satisfied: folium in c:\users\anhbv\anaconda3\lib\site-packages (0.19.6) Requirement already satisfied: branca>=0.6.0 in c:\users\anhbv\anaconda3\lib\site-packages (from folium) (0.8.1) Requirement already satisfied: jinja2>=2.9 in c:\users\anhbv\anaconda3\lib\site-packages (from folium) (3.1.4) Requirement already satisfied: numpy in c:\users\anhbv\anaconda3\lib\site-packages (from folium) (1.26.4) Requirement already satisfied: requests in c:\users\anhbv\anaconda3\lib\site-packages (from folium) (2.32.3) Requirement already satisfied: xyzservices in c:\users\anhbv\anaconda3\lib\site-packages (from folium) (2022.9.0) Requirement already satisfied: MarkupSafe>=2.0 in c:\users\anhbv\anaconda3\lib\site-packages (from jinja2>=2.9->folium) (2.1.3) Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\anhbv\anaconda3\lib\site-packages (from requests->folium) (3.3.2) Requirement already satisfied: idna<4,>=2.5 in c:\users\anhbv\anaconda3\lib\site-packages (from requests->folium) (3.7) Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\anhbv\anaconda3\lib\site-packages (from requests->folium) (2.2.3) Requirement already satisfied: certifi>=2017.4.17 in c:\users\anhbv\anaconda3\lib\site-packages (from requests->folium) (2025.1.31)
Load and Preview Data
In [6]:
import pandas as pd
import folium
from folium import plugins
file_path = r'C:\Users\anhbv\Downloads\Reported_Crime__STARS_Category_Offenses__20250524.csv'
df = pd.read_csv(file_path)
# Preview
df.head()
Out[6]:
| Incident_No | DateReported | DateFrom | DateTo | CLSD | BEAT | SECTION | STARS_CATEGORY | DAY_OF_WEEK | CPD_Neighborhood | Hour_From | Hour_To | LATITUDE_X | LONGITUDE_X | Address_X | type | NIBRSUCRCODE | SNA_Neighborhood | CC_Neighborhood | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2024-INC-000149 | 6/4/2024 14:33 | 5/3/2024 6:00 | 5/3/2024 8:00 | EARLY_CLOSED | CBS | 2913.49 | Part 2 | Tuesday | CBD/RIVERFRONT | 6.0 | 8.0 | 39.1067 | -84.5097 | 2XX E 9TH ST | Part 2 | 26F | Downtown | Downtown |
| 1 | 2024-INC-000477 | 6/8/2024 12:22 | 4/20/2024 0:00 | 4/21/2024 0:00 | EARLY_CLOSED | D3B2 | 2913.49 | Part 2 | Saturday | EAST PRICE HILL | 0.0 | 0.0 | 39.1047 | -84.5696 | 7XX FAIRBANKS AVE | Part 2 | 26F | East Price Hill | East Price Hill |
| 2 | 2024-INC-001607 | 6/21/2024 14:42 | 6/20/2024 14:08 | 6/20/2024 14:25 | EARLY_CLOSED | D3B4 | 2913.49 | Part 2 | Friday | MILLVALE | 14.0 | 14.0 | 39.1488 | -84.5523 | 19XX MILLVALE CT | Part 2 | 26F | Millvale | Millvale |
| 3 | 2024-INC-001801 | 6/23/2024 14:47 | 5/28/2024 0:00 | 6/4/2024 23:59 | EARLY_CLOSED | D3B4 | 2913.49 | Part 2 | Sunday | ENGLISH WOODS | 0.0 | 23.0 | 39.1414 | -84.5585 | 19XX SUTTER AVE | Part 2 | 26F | English Woods_North Fairmount | English Woods |
| 4 | 2024-INC-002557 | 7/2/2024 23:51 | 7/2/2024 13:20 | 7/2/2024 23:51 | EARLY_CLOSED | D4B2 | 2913.49 | Part 2 | Tuesday | SPRING GROVE VILLAGE | 13.0 | 23.0 | 39.1718 | -84.5175 | 7XX MCMAKIN AVE | Part 2 | 26F | Spring Grove Village | Spring Grove Village |
Clean Data
In [8]:
# We remove rows with missing coordinates.
# Keep only rows with valid coordinates
df_clean = df[df['LATITUDE_X'].notna() & df['LONGITUDE_X'].notna()]
print("Rows before:", len(df))
print("Rows after cleaning:", len(df_clean))
Rows before: 24186 Rows after cleaning: 24083
Interactive Crime Map
In [10]:
# Create map centered on Cincinnati
cincinnati_map = folium.Map(location=[39.1031, -84.5120], zoom_start=12)
# Create marker cluster
incidents = plugins.MarkerCluster().add_to(cincinnati_map)
# Add each crime as a marker
for lat, lng, label in zip(df_clean['LATITUDE_X'], df_clean['LONGITUDE_X'], df_clean['STARS_CATEGORY']):
folium.Marker(
location=[lat, lng],
popup=label
).add_to(incidents)
# Display the map
cincinnati_map
Out[10]:
Make this Notebook Trusted to load map: File -> Trust Notebook